package com.multiplayer.dao.impl;

import java.util.List;

import com.multiplayer.dao.IAnnouncementDao;
import com.multiplayer.entity.Announcement;
import com.multiplayer.tools.DBTools;
import com.multiplayer.tools.PageData;

/**
 * 
 * @author 温在鑫
 *@version   [版本号, 2020-05-08]
 *公告操作实现类
 *
 *@author 刘铁辉
 *@version   [版本号, 2020-05-09]
 *公告操作实现类方法实现
 */
public class AnnouncementDaoImpl implements IAnnouncementDao{

	@Override
	public boolean publishAnnouncement(Announcement announcement) {
		//添加公告
		String sql="insert into announcement values(?,?,?,?,?);";
		int affectRows = DBTools.exUpdate(sql, announcement.getTid(),announcement.getAno(),announcement.getTdate(),announcement.getTinfo(),announcement.getTstatus());
		return affectRows>0;
	}

	@Override
	public boolean deleteAnnouncementById(String announcementId) {
		// 通过ID删除公告
		String sql="delete from announcement where tid=?";
		int affectRows=DBTools.exUpdate(sql, announcementId);
		return affectRows>0;
	} 

	@Override
	public boolean editAnnouncement(Announcement announcement) {
		//修改公告
		String sql="update announcement set ano=?,tDate=?,tinfo=?,tstatus=? where tid=? ";
		int affectRows=DBTools.exUpdate(sql, announcement.getAno(),announcement.getTdate(),announcement.getTinfo(),announcement.getTstatus(),announcement.getTid());
		return affectRows>0;
	}

	@Override
	public List<Announcement> queryAnnouncementByKeywords(String keywords) {
		// 关键字查询公告sql
		String sql="select * from announcement where tinfo like ?";
		List<Announcement> annlist=(List<Announcement>) DBTools.exQuery(sql, Announcement.class, "%"+keywords+"%");
	    return annlist; 
	}

	@Override
	public PageData<Announcement> getAllAnnouncement(int page, int pageSize, String keywords) {
		//分页查询公告信息
		String sql = "select * from announcement where tinfo like ? order by tdate desc";
		PageData<Announcement> pd = DBTools.exQueryByPage(sql, Announcement.class, page, pageSize, "%"+keywords+"%");
		return pd;
	}

}
